{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-24T08:34:03.620142Z",
     "start_time": "2025-10-24T08:34:03.595940Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "\n",
    "df1 = pd.DataFrame([['李明','M',18,'北京'],\n",
    "                    ['张华','M',19,'天津'],\n",
    "                    ['刘涛','F',20,'上海'],\n",
    "                    ['王阳','F',14,'广州'],\n",
    "                    ['李春','F',16,'深圳']],\n",
    "                    index=['one', 'two', 'three', 'four','five'],\n",
    "                    columns=['name','gender','age','city'])\n",
    "print(df1\n",
    "    )"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      name gender  age city\n",
      "one     李明      M   18   北京\n",
      "two     张华      M   19   天津\n",
      "three   刘涛      F   20   上海\n",
      "four    王阳      F   14   广州\n",
      "five    李春      F   16   深圳\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-24T08:39:15.660005Z",
     "start_time": "2025-10-24T08:39:15.651813Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data=df1[['name']][:3]\n",
    "print(data)\n",
    "data=df1[['gender','age']][1:3]\n",
    "print(data\n",
    ")\n",
    "\n"
   ],
   "id": "f7a8109f321e4664",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      name\n",
      "one     李明\n",
      "two     张华\n",
      "three   刘涛\n",
      "      gender  age\n",
      "two        M   19\n",
      "three      F   20\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-24T08:42:08.106166Z",
     "start_time": "2025-10-24T08:42:08.092151Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data=df1.loc['one',['gender','age']]\n",
    "print(data)"
   ],
   "id": "cecad87112e62ebb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gender     M\n",
      "age       18\n",
      "Name: one, dtype: object\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-24T08:45:17.851712Z",
     "start_time": "2025-10-24T08:45:17.843855Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data=df1.loc[df1['age']>18,['gender','age']]\n",
    "print(data)"
   ],
   "id": "df27c43cf686c653",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      gender  age\n",
      "two        M   19\n",
      "three      F   20\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-24T09:20:46.948107Z",
     "start_time": "2025-10-24T09:20:46.940389Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data=df1.iloc[3,[3,1,2]]\n",
    "print(\"\\n\",data)"
   ],
   "id": "ea03eb4cfd35c22e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " city      广州\n",
      "gender     F\n",
      "age       14\n",
      "Name: four, dtype: object\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-24T09:23:57.732381Z",
     "start_time": "2025-10-24T09:23:57.717454Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data=df1.iloc[:,:3][df1['age']>18]\n",
    "print(data)"
   ],
   "id": "6c0104492b1bd987",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      name gender  age\n",
      "two     张华      M   19\n",
      "three   刘涛      F   20\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "64ca1c57ba78f601"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
